package com.audi.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.audi.R;

public class AddDeviceViewPagerAdapter extends
			PagerAdapter {
	private Context mContext;
	private int mPage = 4;

	public AddDeviceViewPagerAdapter(
				Context context) {
		mContext = context;
	}

	@Override
	public void destroyItem(View container,
				int position,
				Object object) {
		((ViewPager) container)
					.removeView((View) object);
	}

	@Override
	public int getCount() {
		return mPage;
	}

	@Override
	public boolean isViewFromObject(View arg0,
				Object arg1) {
		return arg0 == ((View) arg1);
	}

	@SuppressLint("InflateParams")
	@Override
	public Object instantiateItem(View container,
				int position) {
		View iv = null;
		switch (position) {
		case 0:
			iv = LayoutInflater
						.from(mContext)
						.inflate(R.layout.new_device_page,
									null);

			break;
		case 1:
			iv = LayoutInflater
						.from(mContext)
						.inflate(R.layout.new_device_page,
									null);
			break;
		case 2:
			iv = LayoutInflater
						.from(mContext)
						.inflate(R.layout.new_device_page,
									null);
			break;
		case 3:
		default:
			iv = LayoutInflater
						.from(mContext)
						.inflate(R.layout.new_device_page,
									null);
			break;
		}
		ImageView imageClose = (ImageView) iv
					.findViewById(R.id.img_add_device_close);
		imageClose.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				((Activity) mContext).finish();
			}
		});
		iv.setTag(position);
		((ViewPager) container).addView(iv);
		return iv;
	}
}
